var JwtStrategy = require('passport-jwt').Strategy,
    ExtractJwt = require('passport-jwt').ExtractJwt;
const {secretOrKey} = require('../../config/db')
const {comMysql} = require("../../db/mysql")


const opts = {}
opts.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken();
//密匙 靠这个解开token
opts.secretOrKey = secretOrKey;
module.exports=(passport)=>{
  passport.use(new JwtStrategy(opts,async function(jwt_payload, done) {
    let sql=`select * from users where id=? and username = ?`
    arr=[jwt_payload.id,jwt_payload.username]
    let data=await comMysql(sql,arr);
    let user=data[0]
    if(user){
      return done(null,user);
    }else{
      return done(null,false);
    }
    
}));
}
